import type { FieldRule } from 'vant'
// 导出一些校验规则
// 手机号的校验规则
export const mobileRule: FieldRule[] = [
  {
    required: true,
    message: '请输入手机号'
  },
  {
    pattern: /^1[3-9]\d{9}$/,
    message: '请输入正确的手机号'
  }
]
// 密码的校验规则
export const passwordRule: FieldRule[] = [
  { required: true, message: '请输入密码' },
  {
    pattern: /^\w{8,24}$/,
    message: '请输入8-24位密码'
  }
]

// 验证码的校验规则
export const codeRule: FieldRule[] = [
  { required: true, message: '请输入验证码' },
  {
    pattern: /^\d{6}$/,
    message: '请输入6位数字验证码'
  }
]

// 姓名的校验规则
export const nameRule: FieldRule[] = [
  { required: true, message: '请输入姓名', trigger: ['onBlur'] },
  {
    pattern: /^(?:[\u4e00-\u9fa5·]{2,16})$/,
    message: '请输入中文姓名',
    trigger: ['onBlur']
  }
]

// 身份证号码的校验规则
export const idCardRule: FieldRule[] = [
  {
    required: true,
    message: '请输入身份证号码',
    trigger: ['onBlur']
  },
  {
    pattern:
      /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/,
    message: '请输入合法身份证号码',
    trigger: ['onBlur']
  }
]
